package com.xiaofei.controller;
import com.xiaofei.Tools.Result;
import com.xiaofei.pojo.emp;
import com.xiaofei.pojo.empPage;
import com.xiaofei.pojo.pageBean;
import com.xiaofei.service.insterface.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
public class EmpController {
    @Autowired
    private EmpService empService;
    /*
    分页查询员工
     */
    @GetMapping("/emps")
    public Result getList(empPage emp){
        pageBean newEmp = empService.page(emp);
        log.info(newEmp.toString());
        return Result.success(newEmp);
    }
    /*
    删除员工
     */
    @DeleteMapping("/emps")
    public Result deleteByIds(@RequestParam List<Integer> ids){
        log.info("ids:{}",ids);
        empService.deleteByIds(ids);
        log.info("删除成功");
        return Result.success();
    }
    /*
    增加员工
     */
    @PostMapping("/emps")
    public Result addEmp(@RequestBody emp e){
        log.info("要添加的员工对象:{}",e);
        empService.addEmp(e);
        return Result.success();
    }
    /*
    修改员工信息
     */
    @GetMapping("/emps/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("id:{}",id);
        emp e = empService.getById(id);
        return Result.success(e);
    }
    @PutMapping("/emps")
    public Result updateEmp(@RequestBody emp e){
        log.info("修改员工信息:{}",e);
        empService.updateEmp(e);
        return Result.success();
    }
}












